<?php
//网站目录
$www_file='/var/www/workorders/';
$logs = '/mnt/foot/logs/workorder.txt';
file_put_contents($logs,date('Y-m-d H:i:s').'============== update start ========='.PHP_EOL.PHP_EOL,FILE_APPEND);

//自定义字串掩码 用于验证
$access_token = 'QhNO8YHqym5PHQQsexapF7041xOhzm62DRH';

// 获取请求端的secret token
$client_token = $_SERVER["HTTP_X_GITLAB_TOKEN"];
//验证token 有错就写进日志并退出
if ($client_token !== $access_token)
{
    echo "error 403";
    file_put_contents($logs, "Invalid token [{$client_token}]".PHP_EOL.PHP_EOL, FILE_APPEND);
    exit(0);
}
//获取请求端发送来的信息，具体格式参见gitlab的文档
$json = file_get_contents('php://input');
$data = json_decode($json, true);

//执行shell命令并把返回信息写进日志
$output=shell_exec(" cd $www_file && git pull origin test  2>&1");
print_r($output);
file_put_contents($logs,$output.PHP_EOL.PHP_EOL, FILE_APPEND);
//fwrite($fs, 'Info:'. $output.PHP_EOL);

//fwrite($fs,PHP_EOL. '================ Update End ==============='.PHP_EOL.PHP_EOL);

//$fs and fclose($fs);

?>
